package thread;

public class Demo41 {

    private static int total = 0;

    public static void main(String[] args) throws InterruptedException {
        //直接使用Runnable实现上述1+2+3+4+...+1000
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                int sum = 0;
                for (int i = 1; i < 1000; i++) {
                    sum+=i;
                }
                total = sum;
            }
        };

        Thread t =new Thread(runnable);
        t.start();
        t.join();
        System.out.println("total = "+total);
    }
}
